package com.tech4u.edu4u_demo;

import android.util.Log;

import com.iflytek.cloud.RecognizerResult;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.LinkedHashMap;

public class SpeechUtils {


    public static String printResult(RecognizerResult results) {
        HashMap<String, String> mIatResults = new LinkedHashMap<String, String>();
        String text = JsonParser.parseIatResult(results.getResultString());

        String sn = null;
        // 读取json结果中的sn字段
        try {
            JSONObject resultJson = new JSONObject(results.getResultString());
            sn = resultJson.optString("sn");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        mIatResults.put(sn, text);

        StringBuffer resultBuffer = new StringBuffer();
        for (String key : mIatResults.keySet()) {
            resultBuffer.append(mIatResults.get(key));
        }

        Log.e("dime", "语音转文字:" + resultBuffer.toString());
        return resultBuffer.toString();
    }

}
